package com.mlnx.transport.config;

import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;

import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;

import lombok.Data;

/**
 * Created by amanda.shan on 2020/3/19.
 */
@Data
public abstract class AbstractMongoConfig {

    private String uri;

    /*
     * Method that creates MongoDbFactory Common to both of the MongoDb
     * connections
     */
    public MongoDbFactory mongoDbFactory() throws Exception {

//        ServerAddress serverAddress = new ServerAddress(host, port);
//        List<MongoCredential> mongoCredentialList = new ArrayList<>();
//        mongoCredentialList.add(MongoCredential.createCredential(username, database, password.toCharArray()));
//        return new SimpleMongoDbFactory(new MongoClient(serverAddress, mongoCredentialList), database);

        return new SimpleMongoDbFactory(new MongoClient(new MongoClientURI(uri)), "mlnx_data");
    }

    /*
     * Factory method to create the MongoTemplate
     */
    abstract public MongoTemplate getMongoTemplate() throws Exception;


}
